package com.ruoyi.web.controller.novel;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysNovelSystemMsg;
import com.ruoyi.system.service.ISysNovelSystemMsgService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 系统消息Controller
 *
 * @author chj
 * @date 2022-11-15
 */
@RestController
@RequestMapping("/novel/msg")
public class SysNovelSystemMsgController extends BaseController
{
    @Autowired
    private ISysNovelSystemMsgService sysNovelSystemMsgService;

    /**
     * 查询系统消息列表
     */
    @PreAuthorize("@ss.hasPermi('novel:msg:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysNovelSystemMsg sysNovelSystemMsg)
    {
        startPage();
        List<SysNovelSystemMsg> list = sysNovelSystemMsgService.selectSysNovelSystemMsgList(sysNovelSystemMsg);
        return getDataTable(list);
    }

    /**
     * 导出系统消息列表
     */
    @PreAuthorize("@ss.hasPermi('novel:msg:export')")
    @Log(title = "系统消息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysNovelSystemMsg sysNovelSystemMsg)
    {
        List<SysNovelSystemMsg> list = sysNovelSystemMsgService.selectSysNovelSystemMsgList(sysNovelSystemMsg);
        ExcelUtil<SysNovelSystemMsg> util = new ExcelUtil<SysNovelSystemMsg>(SysNovelSystemMsg.class);
        util.exportExcel(response, list, "系统消息数据");
    }

    /**
     * 获取系统消息详细信息
     */
    @PreAuthorize("@ss.hasPermi('novel:msg:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysNovelSystemMsgService.selectSysNovelSystemMsgById(id));
    }

    /**
     * 新增系统消息
     */
    @PreAuthorize("@ss.hasPermi('novel:msg:add')")
    @Log(title = "系统消息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysNovelSystemMsg sysNovelSystemMsg)
    {
        return toAjax(sysNovelSystemMsgService.insertSysNovelSystemMsg(sysNovelSystemMsg));
    }

    /**
     * 修改系统消息
     */
    @PreAuthorize("@ss.hasPermi('novel:msg:edit')")
    @Log(title = "系统消息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysNovelSystemMsg sysNovelSystemMsg)
    {
        return toAjax(sysNovelSystemMsgService.updateSysNovelSystemMsg(sysNovelSystemMsg));
    }

    /**
     * 删除系统消息
     */
    @PreAuthorize("@ss.hasPermi('novel:msg:remove')")
    @Log(title = "系统消息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysNovelSystemMsgService.deleteSysNovelSystemMsgByIds(ids));
    }
}
